package psi.common;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;

import psi.controllers.BizlogController;
import psi.controllers.HomeController;
import psi.controllers.IndexController;
import psi.controllers.MainMenuController;
import psi.controllers.PermissionController;
import psi.controllers.PortalController;
import psi.controllers.UserController;

public class PSIConfig extends JFinalConfig {

	@Override
	public void configConstant(Constants me) {
		PropKit.use("psi.properties");
		me.setDevMode(PropKit.getBoolean("devMode", false));
	}

	@Override
	public void configRoute(Routes me) {
		me.add("/", IndexController.class);
		me.add("/Home", HomeController.class, "/View/index");
		me.add("/Home/Bizlog", BizlogController.class, "/View/bizlog");
		me.add("/Home/MainMenu", MainMenuController.class);
		me.add("/Home/Permission", PermissionController.class, "/View/permission");
		me.add("/Home/Portal", PortalController.class);
		me.add("/Home/User", UserController.class, "/View/user");
	}

	@Override
	public void configPlugin(Plugins me) {
		// 配置C3p0数据库连接池插件
		C3p0Plugin c3p0Plugin = new C3p0Plugin(PropKit.get("jdbcUrl"), PropKit.get("user"),
				PropKit.get("password").trim());
		me.add(c3p0Plugin);

		// 配置ActiveRecord插件
		ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
		me.add(arp);
	}

	@Override
	public void configInterceptor(Interceptors me) {
		me.addGlobalActionInterceptor(new AuthInterceptor());
		me.addGlobalActionInterceptor(new SessionInterceptor());
	}

	@Override
	public void configHandler(Handlers me) {

	}
}
